package com.empire.module.spider.service.lotterybasketballmatchsporttery;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.spider.controller.app.lotterybasketballmatchsporttery.vo.*;
import com.empire.module.spider.dal.dataobject.lotterybasketballmatchsporttery.LotteryBasketballMatchSportteryDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.spider.dal.mysql.lotterybasketballmatchsporttery.LotteryBasketballMatchSportteryMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.spider.enums.ErrorCodeConstants.*;

/**
 * 篮球竞猜 Service 实现类
 *
 * @author 无敌
 */
@Service
@Validated
public class LotteryBasketballMatchSportteryServiceImpl implements LotteryBasketballMatchSportteryService {

    @Resource
    private LotteryBasketballMatchSportteryMapper lotteryBasketballMatchSportteryMapper;

    @Override
    public String createLotteryBasketballMatchSporttery(AppLotteryBasketballMatchSportterySaveReqVO createReqVO) {
        // 插入
        LotteryBasketballMatchSportteryDO lotteryBasketballMatchSporttery = BeanUtils.toBean(createReqVO, LotteryBasketballMatchSportteryDO.class);
        lotteryBasketballMatchSportteryMapper.insert(lotteryBasketballMatchSporttery);
        // 返回
        return lotteryBasketballMatchSporttery.getMatchId();
    }

    @Override
    public void updateLotteryBasketballMatchSporttery(AppLotteryBasketballMatchSportterySaveReqVO updateReqVO) {
        // 校验存在
        validateLotteryBasketballMatchSportteryExists(updateReqVO.getMatchId());
        // 更新
        LotteryBasketballMatchSportteryDO updateObj = BeanUtils.toBean(updateReqVO, LotteryBasketballMatchSportteryDO.class);
        lotteryBasketballMatchSportteryMapper.updateById(updateObj);
    }

    @Override
    public void deleteLotteryBasketballMatchSporttery(String id) {
        // 校验存在
        validateLotteryBasketballMatchSportteryExists(id);
        // 删除
        lotteryBasketballMatchSportteryMapper.deleteById(id);
    }

    private void validateLotteryBasketballMatchSportteryExists(String id) {
        if (lotteryBasketballMatchSportteryMapper.selectById(id) == null) {
            throw exception(LOTTERY_BASKETBALL_MATCH_SPORTTERY_NOT_EXISTS);
        }
    }

    @Override
    public LotteryBasketballMatchSportteryDO getLotteryBasketballMatchSporttery(String id) {
        return lotteryBasketballMatchSportteryMapper.selectById(id);
    }

    @Override
    public PageResult<LotteryBasketballMatchSportteryDO> getLotteryBasketballMatchSportteryPage(AppLotteryBasketballMatchSportteryPageReqVO pageReqVO) {
        return lotteryBasketballMatchSportteryMapper.selectPage(pageReqVO);
    }

    @Override
    public List<LotteryBasketballMatchSportteryDO> getList() {
        return List.of();
    }

}
